package prefix.integration.wm;

import java.math.BigDecimal;

import models.WmTransaction;
import models.WmWallet;

public abstract class AbstractWalletManager {

    private static AbstractWalletManager manager;

    public static AbstractWalletManager getInstance() {
        if (manager == null)
            return new WalletManager();
        return manager;
    }

    public enum WMStatus {
        PENDING,
        EXECUTED,
        FAILED,
        UNKNOWN;
    }

    public static class ExecutionStatus {
        private String m_extID = null;

        private BigDecimal m_amount = null;

        private int m_state = -1;

        private String m_accountForActivity;

        private BigDecimal m_closingBalalnce;

        // ==========================================================================
        public ExecutionStatus(String extid, BigDecimal amount, int state, String walletID, BigDecimal closingBalance) {
            this.m_extID = extid;
            this.m_amount = amount;
            this.m_state = state;
            this.m_accountForActivity = walletID;
            this.m_closingBalalnce = closingBalance;
        }

        public String getExtID() {
            return this.m_extID;
        }

        public BigDecimal getAmount() {
            return this.m_amount;
        }

        public int getState() {
            return this.m_state;
        }

        public long getAccountForActivity() {
            return Long.parseLong(this.m_accountForActivity);
        }

        public BigDecimal getAccountClosingBalance() {
            return this.m_closingBalalnce;
        }
    }

    abstract public Integer createWallet(Integer walletId, String name, WmWallet.Type type) throws WMException;

    abstract public ExecutionStatus executeAddFunds(Integer fromWalletId, Integer toWalletId, BigDecimal amount)
            throws WMException;

    abstract public ExecutionStatus executeWithdrawFunds(Integer transId) throws WMException;

    abstract public ExecutionStatus rollbackWithdrawl(Integer transId) throws WMException;

    abstract public Integer createWithdrawl(Integer fromWalletId, Integer toWalletId, BigDecimal amount)
            throws WMException;

    abstract public BigDecimal getBalance(Integer walletId);

    abstract public BigDecimal getBalancePendingWithdrawl(Integer walletId);

    abstract public BigDecimal getBalancePendingInvest(Integer walletId);

    abstract public ExecutionStatus transferPendingInvestFunds(Integer fromWalletId, Integer toWalletId,
            BigDecimal amount) throws WMException;

    abstract public ExecutionStatus pushFundsToBank(Integer fromWalletId, Integer toWalletId, BigDecimal amount)
            throws WMException;

    abstract public void getWMStatus();

    abstract public ExecutionStatus fundsTransferToSystem(Integer fromWalletId, Integer toWalletId, BigDecimal amount)
            throws WMException;

    abstract public ExecutionStatus transferFunds(Integer fromWalletId, Integer toWalletId, BigDecimal amount)
            throws WMException;
}
